package avicit.bdp.dds.dao.mapper;

import avicit.bdp.common.base.BaseDAO;
import avicit.bdp.common.dto.PythonResourceDTO;
import avicit.bdp.dds.dao.entity.Resource;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * resource mapper interface
 */
public interface ResourceMapper extends BaseDAO<Resource> {

    /**
     * query resource list
     *
     * @param fullName full name
     * @param userId   userId
     * @param type     type
     * @return resource list
     */
    List<Resource> queryResourceList(@Param("fullName") String fullName,
                                     @Param("userId") String userId,
                                     @Param("type") int type);

    /**
     * query resource list
     *
     * @param userId userId
     * @param type   type
     * @param perm   perm
     * @return resource list
     */
    List<Resource> queryResourceListAuthored(
            @Param("userId") String userId,
            @Param("type") int type,
            @Param("perm") int perm);


    /**
     * resource page
     *
     * @param id        id
     * @param type      type
     * @param searchVal searchVal
     * @return resource page
     */
    Page<Resource> queryResourcePaging(@Param("id") String id,
                                       @Param("type") int type,
                                       @Param("searchVal") String searchVal);

    /**
     * query Authed resource list
     *
     * @param userId userId
     * @return resource list
     */
    List<Resource> queryAuthorizedResourceList(@Param("userId") String userId);

    /**
     * query resource except userId
     *
     * @param userId userId
     * @return resource list
     */
    List<Resource> queryResourceExceptUserId(@Param("userId") String userId);

    /**
     * query tenant code by name
     *
     * @param resName resource name
     * @param resType resource type
     * @return tenant code
     */
    String queryTenantCodeByResourceName(@Param("resName") String resName, @Param("resType") int resType);

    /**
     * list authorized resource
     *
     * @param userId   userId
     * @param resNames resNames
     * @param <T>      T
     * @return resource list
     */
    <T> List<Resource> listAuthorizedResource(@Param("userId") String userId, @Param("resNames") T[] resNames);


    /**
     * list authorized resource
     *
     * @param userId userId
     * @param resIds resIds
     * @param <T>    T
     * @return resource list
     */
    <T> List<Resource> listAuthorizedResourceById(@Param("userId") String userId, @Param("resIds") T[] resIds);

    /**
     * delete resource by id array
     *
     * @param resIds resource id array
     * @return delete num
     */
    int deleteIds(@Param("resIds") String[] resIds);

    /**
     * list children
     *
     * @param direcotyId directory id
     * @return resource id array
     */
    List<Integer> listChildren(@Param("direcotyId") int direcotyId);

    /**
     * query resource by full name or pid
     *
     * @param fullName full name
     * @param type     resource type
     * @return resource
     */
    List<Resource> queryResource(@Param("fullName") String fullName, @Param("type") int type);

    /**
     * list resource by id array
     *
     * @param resIds resource id array
     * @return resource list
     */
    List<Resource> listResourceByIds(@Param("resIds") String[] resIds);

    /**
     * update resource
     *
     * @param resourceList resource list
     * @return update num
     */
    int batchUpdateResource(@Param("resourceList") List<Resource> resourceList);

    /**
     * 查询子对象集合
     *
     * @param directoryId
     * @param keyWords
     * @return
     */
    Page<Resource> getList(@Param("directoryId") String directoryId, @Param("engineId") String engineId, @Param("projectId") String projectId, @Param(
            "keyWords") String keyWords);

    void deleteByIds(@Param("ids") List<String> ids);

    List<Resource> selectByPid(@Param("pid") String pid);

    /**
     * @param lastUpdateTime 上次更新时间
     * @param list           路径列表
     * @return 变更数量
     */
    int countLatestModify(@Param("lastUpdateTime") Date lastUpdateTime, @Param("list") List<String> list);

    /**
     * 通过资源ID列表查询文件全路径列表
     *
     * @param resourceIdList 资源ID列表
     * @return 路径列表
     */
    List<String> selectFullNameByIdList(@Param("resourceIdList") List<String> resourceIdList);

    /**
     * 查询判读文件列表
     *
     * @param projectId
     * @param directoryId
     * @param name
     * @param status
     * @return
     */
    Page<Resource> getFileResList(@Param("projectId") String projectId,
                                  @Param("directoryId") String directoryId,
                                  @Param("name") String name,
                                  @Param("status") Integer status);

    PythonResourceDTO getPythonResourceById(@Param("id") String id);

    void updatePythonResourceById(@Param("id") String id, @Param("status") Integer status);

    List<Resource> getFileListByLatestModify(@Param("lastUpdateTime") Date lastUpdateTime, @Param("list") List<String> list);

}
